package com.lengyue.imakiba.show;

import java.util.List;

import javax.servlet.http.HttpSession;

import com.jfinal.core.Controller;
import com.lengyue.imakiba.data.Dict;
import com.lengyue.imakiba.manage.DictManage;

public class Login extends Controller {
	private static final String USER_ID = "userId";
	private static final String PASSWORD = "password";
	private static final String ERROR_CODE = "errorCode";
	private static final int LOGIN_ERROR = 1;
	public void index()
	{
		render("/WEB-INF/freeMarkerTemplete/login.ftl");
	}
	public void login()
	{
		String userId = getPara("uid");
		String password = getPara("pw");
		if("system".equals(userId)&&"8516620lh".equals(password))
		{
			HttpSession session = getSession();
			session.setAttribute(USER_ID, userId);
			session.setAttribute(PASSWORD,password);
			List<Dict> states = new DictManage().getDictByDictType("state", "asc");
			setAttr("states", states);
			render("/WEB-INF/freeMarkerTemplete/manage.ftl");
		}
		else
		{
			setAttr(ERROR_CODE, LOGIN_ERROR);
			render("/WEB-INF/freeMarkerTemplete/login.ftl");
		}
	}
}
